package com.crm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.crm.entity.Students;
import com.crm.service.StudentsService;
import com.crm.utils.PageUtil;
import com.crm.utils.ResponeMessageUtil;
import com.crm.utils.UUIDUtil;

/**
 * 学生Controller
 */
@RequestMapping("/students")
@RestController
public class StudentsController {

	@Autowired
	private StudentsService studentsService;
	
	/**
	 * 查询网络学生
	 * @param limit
	 * @param page
	 * @param netpusherid 网络咨询角色id 
	 * @param name
	 * @param createTime
	 * @param endDate
	 * @param stustatus
	 * @param ispay
	 * @return
	 */
	@RequestMapping("/getNetPusherIdAll")
	public ResponeMessageUtil getNetPusherIdAll(Integer limit,Integer page,String netpusherid, String name, String createTime, String endDate,
			String stustatus, String ispay) {
		Integer setValue = PageUtil.getSetValue(page, limit);
		return ResponeMessageUtil.ok(studentsService.getCount(netpusherid, null, name, createTime, endDate, stustatus, ispay), studentsService.selectAll(setValue, limit, netpusherid, null, name, createTime, endDate, stustatus, ispay));
	}
	
	/**
	 * 查询我的学生
	 * @param limit
	 * @param page
	 * @param askerid 咨询师角色id
	 * @param name
	 * @param createTime
	 * @param endDate
	 * @param stustatus
	 * @param ispay
	 * @return
	 */
	@RequestMapping("/getAskerIdAll")
	public ResponeMessageUtil getAskerIdAll(Integer limit,Integer page,String askerid, String name, String createTime, String endDate,
			String stustatus, String ispay) {
		Integer setValue = PageUtil.getSetValue(page, limit);
		return ResponeMessageUtil.ok(studentsService.getCount(null, askerid, name, createTime, endDate, stustatus, ispay), studentsService.selectAskersAll(setValue, limit, null, askerid, name, createTime, endDate, stustatus, ispay));
	}
	
	/**
	 * 查询所有学生（咨询经理）
	 * @param limit
	 * @param page
	 * @param name
	 * @param createTime
	 * @param endDate
	 * @param stustatus
	 * @param ispay
	 * @return
	 */
	@RequestMapping("/getStudentsAll")
	public ResponeMessageUtil getStudentsAll(Integer limit,Integer page, String name, String createTime, String endDate,
			String stustatus, String ispay) {
		Integer setValue = PageUtil.getSetValue(page, limit);
		return ResponeMessageUtil.ok(studentsService.getCount(null, null, name, createTime, endDate, stustatus, ispay), studentsService.selectAll(setValue, limit, null, null, name, createTime, endDate, stustatus, ispay));
	}
	
	/**
	 * 我的学生模块修改信息
	 * @param students
	 * @return
	 */
	@RequestMapping("/updateStudents")
	public boolean updateStudents(Students students) {
		return studentsService.update(students)>0?true:false;
	}
	
	/**
	 * 我的学生模块删除信息(当删除的时候，把isValid改成0)
	 * @param students
	 * @return
	 */
	@RequestMapping("/deleteStudents")
	public boolean deleteStudents(Students students) {
		students.setIsvalid("0");
		return studentsService.update(students)>0?true:false;
	}
	
	/**
	 * 我的学生模块创建学生信息
	 * @param students
	 * @return
	 */
	@RequestMapping("/createStudents")
	public boolean createStudents(Students students) {
		students.setId(UUIDUtil.getUUID());
		return studentsService.insert(students)>0?true:false;
	}
	 
}
